home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0070_Do Nothing Again!.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  1KB  |  46 lines

  1. (*
  2. │{$F+}
  3. │PROCEDURE DoNothing; INTERRUPT;
  4. │BEGIN
  5. │END;
  6. │{$F-}
  7.  
  8.  Would you believe that the code in your DoNothing procedure can be
  9.  improved for smaller size and better speed? (No, I'm not kidding,
  10.  please read on.)  The standard preamble and postamble code generated by
  11.  Turbo Pascal for a procedure of type Interrupt pushes a whole wad of
  12.  registers, sets the BP and DS registers, and then undoes it all before
  13.  the IRET.  Your DoNothing procedure compiles to code that looks
  14.  something like this:
  15.  
  16.    { preamble }
  17.        PUSH  AX BX CX DX SI DI DS ES BP
  18.        MOV   BP, SP
  19.        MOV   AX, @DATA
  20.        MOV   DS, AX
  21.    { postamble }
  22.        POP   BP ES DS DI SI DX CX BX AX
  23.        IRET
  24.  
  25.  The following procedure provides identical results and kills the
  26.  overhead.
  27. *)
  28.    {$f+}
  29.    PROCEDURE DoNothing; ASSEMBLER;   { Coded as Int Handler }
  30.      asm
  31.        IRET             { return from interrupt }
  32.      end;
  33.    {$f-}
  34. (*
  35.  With no parameters and no local vars Turbo Pascal generates no preamble
  36.  code, and generates only a long return as postamble.  The resulting
  37.  compiled code from my DoNothing proc looks like this:
  38.  
  39.    IRET
  40.    RET
  41.  
  42.  The difference:  26 bytes and many stack memory accesses for the null
  43.  Interrupt procedure versus only 2 bytes in the null Assembler procedure
  44.  with Iret.  The RET never gets executed, of course.
  45. *)
  46.